/**
 * @author LKQ
 * @date 2022/1/6 22:19
 * @description 将链表全部反转。
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        ListNode l1 = new ListNode(1);
        ListNode l2 = new ListNode(2, l1);
        ListNode l3 = new ListNode(2, l2);
        ListNode l4 = new ListNode(1, l3);
        System.out.println(solution.isPalindrome(l4));
    }

    public boolean isPalindrome(ListNode head) {
        ListNode temp = head;
        ListNode pre = null;
        while (temp != null) {
            pre = new ListNode(temp.val, pre);
            temp = temp.next;
        }

        while (pre != null ) {
            if(pre.val != head.val) {
                return false;
            }
            pre = pre.next;
            head = head.next;
        }
        return true;
    }
}
